package com.example.loki.griddemo;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;

public class MainActivity extends Activity {

    private RecyclerView mRecycler;
    private ArrayList<MyButton> mMyButtons = new ArrayList<>();
    private MyAdapter mMyAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }


    private void initView() {
        mRecycler = (RecyclerView) findViewById(R.id.recycler);
        //这句是关键，用的是GridLayout的布局，列数为3
        mRecycler.setLayoutManager(new GridLayoutManager(MainActivity.this,3));
        mMyAdapter = new MyAdapter(MainActivity.this, mMyButtons);
        mRecycler.setAdapter(mMyAdapter);

    }

    private void initData() {
        //把信息弄进去,这里可以配置多少个，怎样怎样
        for (int i = 0; i < 6; i++) {
            MyButton myButton = new MyButton();
            myButton.text = "充值" + (100 + i);
            if (i == 1) {//假设为每2个时，左上右下都显示
                myButton.isShowLT = true;
                myButton.isShowRB = true;
            }

            if (i == 3) { //为3，只显示左上
                myButton.isShowLT = true;
            }

            if (i == 4) { //为4只显示右下
                myButton.isShowRB = true;
            }

            mMyButtons.add(myButton);
        }

        mMyAdapter.notifyDataSetChanged();

    }

}
